package net.lab1024.sa.admin.module.sast.task.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;
import net.lab1024.sa.admin.module.sast.task.domain.TaskForm;
import net.lab1024.sa.admin.module.sast.task.service.TaskService;
import net.lab1024.sa.admin.module.sast.tool.domain.ToolConfigEntity;
import net.lab1024.sa.admin.module.sast.tool.service.ToolConfigService;
import net.lab1024.sa.base.common.domain.RequestUser;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/task")
@Tag(name = "任务管理")
public class TaskController {

    @Resource
    private TaskService taskService;

    @Resource
    private ToolConfigService toolConfigService;

    @Operation(summary = "任务初始化创建")
    @PostMapping("/init")
    public ResponseDTO<?> init(TaskForm taskForm){
        RequestUser user = SmartRequestUtil.getRequestUser();
        taskService.create(taskForm,user.getUserId());
        return ResponseDTO.ok();
    }
    @Operation(summary = "任务启动")
    @GetMapping("/start")
    public ResponseDTO<?> start(){
        return ResponseDTO.ok();
    }

    /**
     * 通过任务UUID获取与其相关的工具配置
     * @param uuid
     * @return
     */
    @Operation(summary = "通过任务UUID获取与其相关的工具配置")
    @GetMapping("/getToolConf")
    public ResponseDTO<ToolConfigEntity> getToolConf(@PathParam("uuid") String uuid) {
        return ResponseDTO.ok(toolConfigService.getByTaskUuid(uuid));
    }
}
